package com.quxiu.common.core.utils.map;

public class Vector {
    public static double[] sub(double[] a, double[] b) {
        return new double[] {a[0] - b[0], a[1] - b[1]};
    }

    public static double[] add(double[] a, double[] b) {
        return new double[] {a[0] + b[0], a[1] + b[1]};
    }

    public static double[] mult(double[] a, double c) {
        return new double[] {a[0] * c, a[1] * c};
    }

    public static double dot(double[] a, double[] b) {
        return a[0] * b[0] + a[1] * b[1];
    }

    public static double[] normalize(double[] a) {
        double norm = Math.sqrt(a[0] * a[0] + a[1] * a[1]);
        return new double[] {a[0] / norm, a[1] / norm};
    }

    public static double[] perpendicular(double[] a) {
        return new double[] {-a[1], a[0]};
    }
}
